<template>
  <div>
    <el-checkbox-group v-model="roleIds">
      <el-checkbox v-for="item in list" :key="item.id" :label="item.id">{{ item.name }}</el-checkbox>

    </el-checkbox-group>

    <div style="margin-top: 20px; text-align: right">
      <el-button type="primary" @click="hsave">确定</el-button>
      <el-button @click="closeDialog">取消</el-button>
    </div>
  </div>
</template>
<script>
import { getRoles } from '@/api/setting'
import { getUserDetailById } from '@/api/user'
import { assignRoles } from '@/api/employees.js'
export default {
  props: {
    id: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      list: [],
      roleIds: []
    }
  },

  methods: {
    // 保持更新
    async hsave() {
      await assignRoles({ id: this.id, roleIds: this.roleIds })
      this.$emit('close')
    },
    closeDialog() {
      this.$emit('close')
    },
    async loadRoles() {
      const res = await getRoles({ page: 1, pagesize: 100 })
      console.log(res)
      this.list = res.data.rows
      const resp = await getUserDetailById(this.id)
      console.log(resp)
      this.roleIds = resp.data.roleIds
    }
  }
}
</script>
